<template>
	<basic-container>
		<avue-crud :option="option" :data="data" :page="page" ref="crud" @search-change="searchChange" @search-reset="searchReset"
		 @current-change="currentChange" @size-change="sizeChange" @on-load="onLoad">
		</avue-crud>
	</basic-container>
</template>

<script>
	import request from '@/router/axios';

	export default {
		props: {
			pid: "",
			search: true
		},
		data() {
			return {
				query: {},
				page: {
					pageSize: 10,
					currentPage: 1,
					total: 0
				},
				option: {
					searchMenuSpan: 12,
					border: true,
					index: true,
					menu: false,
					addBtn: false,
					refreshBtn: false,
					excelBtn: true,
					menuWidth: '150px',
					showSummary: true,
					sumColumnList: [{
						name: 'quantity',
						type: 'sum'
					}, {
						name: 'toQty',
						type: 'sum'
					}, {
						name: 'downQty',
						type: 'sum'
					}],
					column: [{
							label: "库位",
							prop: "localCode",
							width: 100
						},
						{
							label: "条码",
							prop: "barCode",
							width: 120
						},
						{
							label: "库存数量",
							prop: "quantity",
							width: 80
						},
						{
							label: "计划移出",
							prop: "toQty",
							width: 80
						},
						{
							label: "实际下架",
							prop: "downQty",
							width: 80
						},
						{
							label: "下架时间",
							prop: "downedOn",
							width: 155
						},
						{
							label: "备注",
							prop: "remark"
						}
					]
				},
				data: []
			};
		},
		created() {},
		methods: {
			rowSave(row, loading, done) {
				request({
					url: '2/api/WmsMoveDetail/add',
					method: 'post',
					data: row
				}).then(() => {
					loading();
					this.onLoad(this.page);
					done();
				}, error => {
					done();
					console.log(error);
				});
			},
			rowUpdate(row, index, loading, done) {
				return request({
					url: '2/api/WmsMoveDetail/edit',
					method: 'post',
					data: row
				}).then(() => {
					loading();
					this.onLoad(this.page);
				}, error => {
					done();
					console.log(error);
				});
			},
			rowDel(row) {
				this.$confirm("确定数据删除?", {
						confirmButtonText: "确定",
						cancelButtonText: "取消",
						type: "warning"
					})
					.then(() => {
						return request({
							url: '2/api/WmsMoveDetail/remove',
							method: 'post',
							params: {
								ids: row.id
							}
						});
					})
					.then(() => {
						this.onLoad(this.page);
					});
			},
			searchReset() {
				this.query = {};
				this.page.currentPage = 1;
				this.onLoad(this.page);
			},
			searchChange(params, done) {
				this.page.currentPage = 1;
				this.query = params;
				this.onLoad(this.page);
				done();
			},
			currentChange(currentPage) {
				this.page.currentPage = currentPage;
			},
			sizeChange(pageSize) {
				this.page.pageSize = pageSize;
			},
			onLoad(page) {
				request({
					url: '2/api/WmsMoveDetail/getpages',
					method: 'get',
					params: {
						type: this.pid == undefined ? '' : this.pid,
						page: page.currentPage,
						limit: page.pageSize
					}
				}).then(res => {
					const data = res.data
					this.data = data.data;
					this.page.total = data.remark;
				});
			}
		},
		watch: {
			pid(val) {
				if (val !== undefined && val !== null && val !== "") {
					this.page.currentPage = 1;
					this.onLoad(this.page);
				}
			}
		}
	};
</script>

<style>
</style>
